-- card: 3014 from stack: in -- bmap block id: 3178 -- flags: 0000 -- background id: 2806 -- name: -- part 1 (field) -- low flags: 05 -- high flags: 2004 -- rect: left=95 top=79 right=110 bottom=171 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 3 -- text size: 18 -- style flags: 256 -- line height: 24 -- part name: Numeric view ----- HyperTalk script ----- on upDate put cd fld "Model" into me end upDate -- part 2 (field) -- low flags: 05 -- high flags: 0000 -- rect: left=232 top=175 right=193 bottom=262 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: bar feedback ----- HyperTalk script ----- on feedback X if X ≠ empty then set style of me to "Rect" put (X-left of cd button "bar index") DIV 10 into me else put empty into me set style of me to "Transparent" end if end feedback on newLeft X set left of me to X end newLeft -- part 3 (field) -- low flags: 04 -- high flags: 0000 -- rect: left=325 top=117 right=247 bottom=510 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Dependent views ----- HyperTalk script ----- on doUpdates repeat with i = 1 to number of lines of me if line i of me is empty or char 1 of line i of me is "-" then next repeat end if select line i of me send "Update" to line i of me end repeat end doUpdates -- part 4 (field) -- low flags: 05 -- high flags: 2000 -- rect: left=434 top=65 right=85 bottom=482 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 65535 -- font id: 3 -- text size: 10 -- style flags: 256 -- line height: 13 -- part name: Model ----- HyperTalk script ----- on increment add 1 to me send "doUpdates" to cd field "Dependent views" end increment on decrement subtract 1 from me send "doUpdates" to cd field "Dependent views" end decrement on setValue n if n ≠ me then put n into me send "doUpdates" to cd field "Dependent views" end if end setValue -- part 5 (button) -- low flags: 00 -- high flags: 2002 -- rect: left=180 top=67 right=92 bottom=196 -- title width / last selected line: 0 -- icon id / first selected line: 16692 / 16692 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: ----- HyperTalk script ----- on mouseUp send "increment" to cd fld "model" end mouseUp -- part 6 (button) -- low flags: 00 -- high flags: 2002 -- rect: left=180 top=96 right=120 bottom=196 -- title width / last selected line: 0 -- icon id / first selected line: 3584 / 3584 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: ----- HyperTalk script ----- on mouseUp send "decrement" to cd fld model end mouseUp -- part 7 (button) -- low flags: 00 -- high flags: 2002 -- rect: left=211 top=175 right=198 bottom=233 -- title width / last selected line: 0 -- icon id / first selected line: 26020 / 26020 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Bar controller ----- HyperTalk script ----- on mouseDown repeat until the mouse is up put item 1 of mouseloc() into X newX X send "feedback" && X to cd fld "bar feedback" end repeat send "feedback" to cd fld "bar feedback" put (X-left of cd button "bar index") DIV 10 into newVal send "SetValue" && newVal to cd fld "Model" end mouseDown on newX X get loc of me put X into item 1 of it set loc of me to it send "newLeft" && right of me-1 to cd fld "bar feedback" end newX -- part 8 (button) -- low flags: 00 -- high flags: 4001 -- rect: left=132 top=153 right=170 bottom=222 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: bar view ----- HyperTalk script ----- on UpDate put card field "Model" into counterValue set width of me to abs(10*counterValue) if counterValue ≥ 0 then set left of me to left of cd button "Bar index" send "newX" && right of me to cd button "Bar Controller" else set right of me to left of cd button "Bar index" send "newX" && left of me to cd button "Bar Controller" end if end UpDate -- part 9 (button) -- low flags: 00 -- high flags: 4000 -- rect: left=132 top=176 right=194 bottom=133 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Bar index -- part 10 (button) -- low flags: 00 -- high flags: 0003 -- rect: left=127 top=278 right=290 bottom=139 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: dial view ----- HyperTalk script ----- on upDate set cursor to busy lock Screen put (4*(cd field "Model")-90)/180*3.142 into A put item 1 of loc of me into x put item 2 of loc of me into y choose select tool drag from x-52, y-52 to x+52, y+52 domenu "Clear picture" choose line tool set linesize to 2 drag from x,y to trunc(x+50*cos(A)),trunc(y+50*sin(A)) choose browse tool end upDate -- part 11 (button) -- low flags: 00 -- high flags: 8002 -- rect: left=199 top=227 right=251 bottom=310 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Dice view ----- HyperTalk script ----- on Update put abs(card field "model") into counterValue if counterValue ≤ 12 then get (counterValue div 2) put rand(it, min(countervalue-1,6)) into Die1 put counterValue-Die1 into Die2 set the icon of card button "Die 1" to "Dice,"&Die1 set the icon of card button "Die 2" to "Dice,"&Die2 else set the icon of card button "Die 1" to empty set the icon of card button "Die 2" to empty end if get card field "model" < 0 set hilite of card button "Die 1" to it set hilite of card button "Die 2" to it end Update function rand i,j -- returns a random integer in the interval i to j return random(j-i+1)-1+i end rand -- part 12 (button) -- low flags: 00 -- high flags: 0000 -- rect: left=211 top=260 right=295 bottom=246 -- title width / last selected line: 0 -- icon id / first selected line: 2104 / 2104 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Die 1 -- part 13 (button) -- low flags: 00 -- high flags: 0000 -- rect: left=260 top=260 right=295 bottom=295 -- title width / last selected line: 0 -- icon id / first selected line: 2105 / 2105 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Die 2 -- part 14 (button) -- low flags: 00 -- high flags: A003 -- rect: left=201 top=306 right=328 bottom=309 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Roll ----- HyperTalk script ----- on mouseUp send "setValue" && random(24)-12 to cd fld "model" end mouseUp -- part 16 (field) -- low flags: 01 -- high flags: 2004 -- rect: left=98 top=0 right=321 bottom=458 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Help ----- HyperTalk script ----- on mouseUp send "mouseUp" to cd button "Help" end mouseUp -- part 17 (button) -- low flags: 00 -- high flags: 6001 -- rect: left=6 top=5 right=27 bottom=29 -- title width / last selected line: 0 -- icon id / first selected line: 25002 / 25002 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Help ----- HyperTalk script ----- on mouseUp if visible of cd fld "Help" then hide cd fld help set hilite of me to false else show cd fld help set hilite of me to true end if end mouseUp -- part contents for card part 4 ----- text ----- 9 -- part contents for card part 3 ----- text ----- card button "Dice view" card field "Numeric view" card button "Bar view" card button "Dial view" -- part contents for card part 1 ----- text ----- 9 -- part contents for card part 16 ----- text ----- MVC Simulation v3 (HC1 version) George Coulouris, October 1990 (george@cs.qmw.ac.uk) A simulation of a Counter with multiple views implemented according to the Model-View-Controller paradigm. There are four views: • the Numeric View shows the counter value in numeric form • the Bar View indicates the value and sign of the counter value by the length of a bar • the dial view indicates the counter value by the angle of the 'needle' • the dice view (thanks to Kostas Karlis for this nice idea)! There are four controllers: • the arrows beside the numeric view (click them) • the arrow below the bar view (drag it) • the "Roll" button gives the counter a random value. Open the script of an object to see its behaviour. The scripts correspond as closely as possible to the behaviour of MVC described in the paper.